package add_init

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/jmoiron/sqlx"
	"log"
)

var db *sqlx.DB

func InitDB() {
	var err error
	db, err = sqlx.Connect(
		"mysql",
		"root:root@tcp(192.168.56.101:3306)/test?charset=utf8mb4")
	if err != nil {
		log.Fatal("数据库连接失败", err)
	}

	db.SetMaxIdleConns(10)
	db.SetMaxOpenConns(20)
}

func GetDB() *sqlx.DB {
	return db
}
